package com.njtoyo.taxi.admin.rest.controller.local_service.commodity;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.local_service.commodity.IsPresentedPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.commodity.isPresented.IsPresentedAddWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.commodity.isPresented.IsPresentedPageWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.commodity.isPresented.IsPresentedUpdateWrapper;
import com.njtoyo.taxi.admin.service.local_service.commodity.IsPresentedService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@RestController
@Api(value = "赠送商品管理", tags = "赠送商品管理")
@RequestMapping("local-service/commodity/is-presented")
public class IsPresentedController {

    @Autowired
    private IsPresentedService isPresentedService;

    @GetMapping("")
    @ApiOperation(value = "赠送商品列表", notes = "商品列表,权限：life_set_present_list")
    @PermissionScope(names = {"life_set_present_list"})
    RestResult<Page<IsPresentedPresenter>> getPage(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                                                   @Valid IsPresentedPageWrapper wrapper) {
        return isPresentedService.getPage(adminUser, wrapper);
    }

    @PostMapping("")
    @ApiOperation(value = "添加赠送商品", notes = "life_set_present_add")
    @PermissionScope(names = {"life_set_present_add"})
    RestResult add(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                   @Valid @RequestBody IsPresentedAddWrapper wrapper) {
        return isPresentedService.add(adminUser, wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "修改赠送商品", notes = "life_set_present_update")
    @PermissionScope(names = {"life_set_present_update"})
    RestResult update(@PathVariable("id") Long id,
                      @Valid @RequestBody IsPresentedUpdateWrapper wrapper) {
        return isPresentedService.update(id, wrapper);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除赠送商品规则", notes = "life_set_present_delete")
    @PermissionScope(names = {"life_set_present_delete"})
    RestResult delete(@PathVariable("id") Long id) {
        return isPresentedService.delete(id);
    }
}
